<template>
	<view class="">
		<!-- 定位城市 -->
		<view class="u-flex u-row-between u-p-20 u-font-28 bg_FFFFFF">
			<view class="u-weight">
				当前位置
			</view>
			<view class="u-flex">
				<view class="">
					<u-icon name="map-fill" size="35" color="#1CC378"></u-icon>
					<text class="">{{location.name}}</text>
				</view>
				<view @click="switchCity('all')" class="u-m-l-20">
					切换到全国
				</view>
			</view>
		</view>
		<view class="u-h-10">
			
		</view>
		<view class="u-p-20 bg_FFFFFF">
			<u-index-list :scrollTop="scrollTop" :index-list="indexList">
				<view v-for="(item, index) in list" :key="index">
					<u-index-anchor :index="item.letter" />
					<view class="list-cell u-border-bottom" v-for="(item1, index1) in item.data" @click.stop="switchCity(item1)" :key="index1">
						{{item1.area_name}}
					</view>
				</view>
			</u-index-list>
		</view>
	</view>
</template>

<script>
	import indexList from "@/common/index.list.js";
	const letterArr = indexList.list.map(val => {
		return val.letter;
	})
	export default {
		data() {
			return {
				location:'',
				// 搜索
				keyword: '',
				scrollTop: 0,
				indexList: [],
				list:[]
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onLoad() {
			this.location=uni.getStorageSync('location')
			this.get_city_area()
		},
		methods: {
			// 输入城市时获取地址
			custom() {
			},
			get_city_area() {
				this.indexList = []
				this.$api.get_city_area({}, res => {
					if (res.data.code == 1) {
						this.indexList = res.data.data.map(val => {
							return val.letter;
						})
						this.list = res.data.data
					}
				})
			},
			switchCity(item){
				if(item=='all'){
					uni.setStorageSync('location',{
						name:'全国',
						latitude:0,
						longitude:0
					})
				}else{
					uni.setStorageSync('location',{
						name: item.area_name,
						latitude: item.lat,
						longitude: item.lng
					})
				}
				uni.setStorageSync('updateCity','1')
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped>
	page {
		background: #F5F5F5FF !important;
	}

	.list-cell {
		display: flex;
		box-sizing: border-box;
		width: 100%;
		padding: 10px 24rpx;
		overflow: hidden;
		color: $u-content-color;
		font-size: 14px;
		line-height: 24px;
		background-color: #fff;
	}
</style>
